package org.jeecg.modules.parameter.biz.controlltr;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.parameter.api.dto.exit.SimExitDto;
import org.jeecg.modules.parameter.api.dto.park.SimParkDto;
import org.jeecg.modules.parameter.api.entity.SimExit;
import org.jeecg.modules.parameter.api.entity.SimPark;
import org.jeecg.modules.parameter.api.vo.exit.SimExitVo;
import org.jeecg.modules.parameter.api.vo.park.SimParkVo;
import org.jeecg.modules.parameter.biz.service.SimLineParkService;
import org.jeecg.modules.parameter.biz.service.SimLineService;
import org.jeecg.modules.parameter.common.api.dto.PatchPO;
import org.jeecg.modules.parameter.common.utils.oConvertUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lsy
 * @date 2024/09/17
 */
@Api(tags = "参数管理-场段管理")
@RestController
@RequestMapping(value = {"/lineParkInfo"}, produces = {"application/json; charset=utf-8"})
@Slf4j
public class SimLineParkController extends JeecgController<SimPark, SimLineParkService> {
    @Resource
    private SimLineParkService parkService;

    @ApiOperation(value = "按线路ID查询场段信息", notes = "按线路ID查询场段信息")
    @PostMapping(value = "/getParkByLineId")
    public Result<List<SimParkVo>> getParkByLineId(@RequestParam(name = "lineId", required = true) String id) {
        List<SimParkVo> simExitVo = oConvertUtils.entityListToModelList(parkService.getParkByLineId(id), SimParkVo.class);
        return Result.ok(simExitVo);
    }

    @ApiOperation(value = "按ID删除场段信息", notes = "按ID删除场段信息")
    @PostMapping(value = "/delPark")
    public Result<String> delPark(@RequestParam(name = "id", required = true) String id) {
        parkService.removeById(id);
        return Result.ok("删除成功");
    }

    @ApiOperation(value = "按ID查询场段信息", notes = "按ID查询场段信息")
    @PostMapping(value = "/queryParkById")
    public Result<SimPark> queryParkById(@RequestParam(name = "id", required = true) String id) {
        return Result.ok(parkService.getById(id));
    }

    @ApiOperation(value = "添加场段", notes = "添加场段")
    @PostMapping(value = "/addPark")
    public Result<String> addPark(@RequestBody SimParkDto simParkDto) {
        parkService.save(oConvertUtils.entityToModel(simParkDto, SimPark.class));
        return Result.ok("保存成功");
    }


    @ApiOperation(value = "修改场段", notes = "修改场段")
    @PutMapping(value = "/updatePark")
    public Result<String> updatePark(@RequestBody PatchPO patchPO) {
        parkService.updatePatch(patchPO);
        return Result.OK("更新成功!");
    }

}
